<template>
  <view style="height: 100%">
    <!-- pages/start/start.wxml -->
    <view class="container">
      <view class="tab-image">
        <image class="bgImages" :src="startURL" />
        <view class="gohome" @tap="goHome">跳过广告 {{ second }}</view>
      </view>
    </view>
  </view>
</template>

<script>
//获取应用实例
var app = getApp();

function startCountdown(that) {
  if (that.timer) clearInterval(that.timer);
  
    that.timer = setInterval(() => {
      if (that.home === 1) {
        clearInterval(that.timer);
        return;
      }
      
      if (that.second <= 0) {
        clearInterval(that.timer);
        uni.switchTab({
          url: "../index/index",
        });
        return;
      }
      
      that.second--;
    }, 1000);
}
export default {
  data() {
    return {
      second: 6,
      home: 0,
      sales: "",
      startURL: "http://49.233.144.92:7791/i/2025/10/26/68fe35d41a3b6.jpg",
    };
  },
  onLoad: function () {
    var that = this;
    startCountdown(that);
    uni.request({
      url: app.globalData.urls + "/banner/list",
      data: {
        key: "mallName",
        type: "start",
      },
      success: function (res) {
        if (res.data.code == 0) {
          that.setData({
            sales: res.data.data,
          });
        }
      },
    });
  },
  beforeDestroy() {
    if (this.timer) clearInterval(this.timer);
  },
  methods: {
    goHome: function () {
      uni.switchTab({
        url: "../index/index",
      });
    },

    tapBanner: function (e) {
      console.log("e.currentTarget.dataset.id =", e.currentTarget.dataset.id);
      if (e.currentTarget.dataset.id != 0) {
        uni.redirectTo({
          url: "pages/index/index",
        });
      }
    },

    homeFun() {
      console.log("占位：函数 home 未声明");
    },
  },
};
</script>
<style>
/* pages/start/start.wxss */
/**start.wxss**/
page,
.container {
  background-color: #fff;
  width: 100%;
  height: 100%;
  display: block;
}

.tab-image {
  width: 100%;
  height: 100vh;
  position: relative;
}

.bgImages {
  width: 100%;
  display: block;
  height: 100vh;
}

.gohome {
  font-size: 24rpx;
  background-color: rgba(0, 0, 0, 0.5);
  color: #fff;
  text-align: center;
  float: right;
  position: absolute;
  right: 10px;
  bottom: 10px;
  border-radius: 20px;
  padding: 3px 8px;
}
</style>
